<?php if(isset($details)): ?>
    <!-- image and rating information -->
    <span class="img drink_img">
	<?php echo anchor('/image/show/' . $drink['details']->id, img(base_url() . 'img/' . $drink['details']->image_path), ''); ?>
	<br>
	<span class="progress">
	    <?php
                /**
                 * RATING
                 * We first check if the user has cast a vote yet, if he hasn't 
                 * the plus and minus chars become anchors and allow him to rate.
                 * If a rating has been made, we show a progress bar indicating
                 * how good/bad that drink has been rated.
                 *  below 25% = red
                 *  below 75% = orange
                 *  above 75% = green
                 */
            
                //rate down button
                if(!$rated)                                                     #user did not rate yet
                    echo anchor('drink/rate?id=' . $details->id, '-', '');
                else                                                            #user already rated this
                    echo '<span rel="tooltip" title="You did already cast a vote.">-</span>';
                
                //rating progress indicator
                echo '<span class="progress-bar ';
                if($rating){                                                    #at least 1 rating is given    
                    //progress bar color switch
                    if($rating->rating < 25)
                        echo 'progress-bar-danger';
                    elseif($rating->rating < 75)
                        echo 'progress-bar-warning';
                    else
                        echo 'progress-bar-success';
                }
                else
                    echo 'progress-bar-info';
                echo '" width="' . $rating->perc . '">' . $rating->perc . ' ('. $rating->count . ')</span>';
                
                //rate up button
                if(!$rated)
                    echo anchor('drink/rate?id=' . $details->id, '-', '');
                else
                    echo '<span rel="tooltip" title="You did already cast a vote.">-</span>';
            ?>
	</span>
    </span>
    
    <!-- author and metadata information -->
    <span class="drink_metadata">
	<?php 
	    echo 'Author: ' . anchor('/user/details/' . $details->user_id, $details->username, '') . '<br>'; 
	    echo 'Created at: '  . date('d.m.Y', strtotime($details->created)) . '<br>';
            echo 'Last update: ';
	    if(!$details->updated) 
                echo 'n/a';
            else
                echo date('d.m.Y', strtotime($details->updated));
	?>
    </span>
    <br>
    <br>
    
    <?php echo (isset($error)) ? '<div class="error">' . $error . '</div><br><br>' : '' ;?>
    <?php echo (isset($success)) ? '<div class="success">' . $success . '</div><br><br>' : '' ;?>
    
    <!-- drink information starts here -->
    <table class="table-striped table-condensed" border="1">
        <tr>
            <th colspan="2">Ingredients:</th>
        </tr>
        <tr>
	    <th>Amount:</th>
            <th>Name:</th>
        </tr>
    <?php 
        //ingredients are being shown here
        foreach($ingredients as $ingredient){
            echo '<tr>
                    <td>' . $ingredient->amount . ' ' . $ingredient->measurand . '</td>';
            echo   '<td>' . $ingredient->name   . ' ' . $ingredient->type . '</td>
                 </tr>';
        }
    ?>
        <tr>
            <th colspan="2">Instructions:</th>
        </tr>
        <tr>
            <td colspan="2">
            <?php 
                if($details->instruction)
                    echo $details->instruction;
                else
                    echo 'No instructions given';
            ?>
	    </td>
        </tr>
    </table>
    <!-- drink information ends here -->


<?php else: ?>
    <div class="error">Sorry, we could not find your drink recipe</div>
<?php endif; ?>

